package com.hqyj.purchase.controller;



import com.hqyj.purchase.model.PurchaseInfo;
import com.hqyj.repertory.model.Repertory;
import frame.purchase.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author qianyexiuci
 * @date 2021/09/08 10:19
 */
@Controller
@RequestMapping("/repertoryController")
public class InGoodsRepertoryController extends BaseController {
    @RequestMapping("/ingoods.do")
    public String repertory(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model){
        int id = Integer.parseInt(request.getParameter("id"));
        PurchaseInfo purchaseInfo = purchaseService.queryPurchaseInfoById(id);
        purchaseInfo.setState("已入库");
        purchaseService.updatePurchase(purchaseInfo);
        String type = "原料";
        Repertory repertory =repertoryService.queryAllByName(purchaseInfo.getTradeName());
        int repertoryNum =repertory.getNumber();
        int num =repertoryNum + purchaseInfo.getPurchaseNum();

        int rows1 = repertoryService.updateRepertory(repertory,purchaseInfo.getTradeName(),num,type,purchaseInfo.getProvider(),purchaseInfo.getTradePrice());
        int rows2 = inRepertoryService.addInRepertory(purchaseInfo);

        List<PurchaseInfo> purchaseInfoList = purchaseService.queryAllPurchaseInfo();
        model.addAttribute("purchaseInfoList",purchaseInfoList);

        return "view/purchase/listPurchase";
    }

}
